package group.itk.vuelogintestbackend.config

import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.web.cors.CorsConfiguration
import org.springframework.web.cors.UrlBasedCorsConfigurationSource
import org.springframework.web.filter.CorsFilter

@Configuration
class CorsConfig {
    @Bean
    fun corsFilter(): CorsFilter {
        val urlBasedCorsConfigurationSource = UrlBasedCorsConfigurationSource()
        val corsConfiguration = CorsConfiguration()
        //允许所有源
        corsConfiguration.addAllowedOrigin("*")
        //允许所有请求头
        corsConfiguration.addAllowedHeader("*")
        //允许所有方法
        corsConfiguration.addAllowedMethod("*")
        urlBasedCorsConfigurationSource.registerCorsConfiguration("/**",corsConfiguration)
        return CorsFilter(urlBasedCorsConfigurationSource)
    }
}
